summaryrefslogtreecommitdiffstats
path: root/tests/test_receive.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_receive.c')
-rw-r--r--tests/test_receive.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/test_receive.c b/tests/test_receive.c
index 1452ed3e..3c6a652a 100644
--- a/tests/test_receive.c
+++ b/tests/test_receive.c
@@ -8,6 +8,8 @@
extern IsoTpShims SHIMS;
extern IsoTpReceiveHandle RECEIVE_HANDLE;
+extern void message_sent(const IsoTpMessage* message, const bool success);
+
extern uint16_t last_can_frame_sent_arb_id;
extern uint8_t last_can_payload_sent;
extern uint8_t last_can_payload_size;
@@ -81,6 +83,70 @@ START_TEST (test_receive_single_frame)
}
END_TEST
+START_TEST (test_receive_multi_frame)
+{
+ const uint8_t data0[CAN_MESSAGE_BYTE_SIZE] = {0x10, 0x14, 0x49, 0x02, 0x01, 0x31, 0x46, 0x4d};
+ IsoTpMessage message0 = isotp_continue_receive(&SHIMS, &RECEIVE_HANDLE, 0x2a, data0, 8);
+ fail_unless(!RECEIVE_HANDLE.completed);
+ fail_unless(!message0.completed);
+ fail_unless(!message_was_received);
+ fail_unless(message0.multi_frame);
+ //make sure flow control message has been sent.
+ ck_assert_int_eq(last_can_frame_sent_arb_id, 0x2a - 8);
+ ck_assert_int_eq(last_can_payload_sent, 0x30);
+
+ const uint8_t data1[CAN_MESSAGE_BYTE_SIZE] = {0x21, 0x43, 0x55, 0x39, 0x4a, 0x39, 0x34, 0x48};
+ IsoTpMessage message1 = isotp_continue_receive(&SHIMS, &RECEIVE_HANDLE, 0x2a, data1, 8);
+ fail_unless(!RECEIVE_HANDLE.completed);
+ fail_unless(!message1.completed);
+ fail_unless(!message_was_received);
+ fail_unless(message1.multi_frame);
+
+ const uint8_t data2[CAN_MESSAGE_BYTE_SIZE] = {0x22, 0x55, 0x41, 0x30, 0x34, 0x35, 0x32, 0x34};
+ IsoTpMessage message2 = isotp_continue_receive(&SHIMS, &RECEIVE_HANDLE, 0x2a, data2, 8);
+ fail_unless(RECEIVE_HANDLE.completed);
+ fail_unless(message2.completed);
+ fail_unless(message_was_received);
+ fail_unless(message2.multi_frame);
+
+ ck_assert_int_eq(last_message_received_arb_id, 0x2a);
+ ck_assert_int_eq(last_message_received_payload_size, 0x14);
+ ck_assert_int_eq(last_message_received_payload[0], 0x49);
+ ck_assert_int_eq(last_message_received_payload[1], 0x02);
+ ck_assert_int_eq(last_message_received_payload[2], 0x01);
+ ck_assert_int_eq(last_message_received_payload[3], 0x31);
+ ck_assert_int_eq(last_message_received_payload[4], 0x46);
+ ck_assert_int_eq(last_message_received_payload[5], 0x4d);
+ ck_assert_int_eq(last_message_received_payload[6], 0x43);
+ ck_assert_int_eq(last_message_received_payload[7], 0x55);
+ ck_assert_int_eq(last_message_received_payload[8], 0x39);
+ ck_assert_int_eq(last_message_received_payload[9], 0x4a);
+ ck_assert_int_eq(last_message_received_payload[10], 0x39);
+ ck_assert_int_eq(last_message_received_payload[11], 0x34);
+ ck_assert_int_eq(last_message_received_payload[12], 0x48);
+ ck_assert_int_eq(last_message_received_payload[13], 0x55);
+ ck_assert_int_eq(last_message_received_payload[14], 0x41);
+ ck_assert_int_eq(last_message_received_payload[15], 0x30);
+ ck_assert_int_eq(last_message_received_payload[16], 0x34);
+ ck_assert_int_eq(last_message_received_payload[17], 0x35);
+ ck_assert_int_eq(last_message_received_payload[18], 0x32);
+ ck_assert_int_eq(last_message_received_payload[19], 0x34);
+}
+END_TEST
+
+START_TEST (test_receive_large_multi_frame)
+{
+ const uint8_t data0[CAN_MESSAGE_BYTE_SIZE] = {0x11, 0x01, 0x49, 0x02, 0x01, 0x31, 0x46, 0x4d};
+ IsoTpMessage message = isotp_continue_receive(&SHIMS, &RECEIVE_HANDLE, 0x2a, data0, 8);
+ //Make sure we don't try to receive messages that are too large and don't send flow control.
+ fail_unless(!can_frame_was_sent);
+ fail_unless(!RECEIVE_HANDLE.completed);
+ fail_unless(!message.completed);
+ fail_unless(!message_was_received);
+ fail_unless(!message.multi_frame);
+}
+END_TEST
+
Suite* testSuite(void) {
Suite* s = suite_create("iso15765");
TCase *tc_core = tcase_create("receive");
@@ -90,6 +156,8 @@ Suite* testSuite(void) {
tcase_add_test(tc_core, test_receive_single_frame);
tcase_add_test(tc_core, test_receive_single_frame_empty_payload);
tcase_add_test(tc_core, test_receive_empty_can_message);
+ tcase_add_test(tc_core, test_receive_multi_frame);
+ tcase_add_test(tc_core, test_receive_large_multi_frame);
suite_add_tcase(s, tc_core);
return s;