diff options
author | Christopher Peplin <chris.peplin@rhubarbtech.com> | 2013-12-27 23:45:17 -0500 |
---|---|---|
committer | Christopher Peplin <chris.peplin@rhubarbtech.com> | 2013-12-28 10:58:02 -0500 |
commit | b44a9890490f57bea76973f8810360c77ca68081 (patch) | |
tree | 53e14b86f80f4277414748421aaee826dcc4838b /tests | |
parent | 37a7e905f653eeb7d923eedaa9f30cdb9fd6de78 (diff) |
Confirm CAN messages are built correctly.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/common.c | 16 | ||||
-rw-r--r-- | tests/test_send.c | 16 |
2 files changed, 23 insertions, 9 deletions
diff --git a/tests/common.c b/tests/common.c index 512adfbc..427d90c9 100644 --- a/tests/common.c +++ b/tests/common.c @@ -8,7 +8,7 @@ IsoTpShims SHIMS; IsoTpHandler ISOTP_HANDLER; uint16_t last_can_frame_sent_arb_id; -uint8_t last_can_payload_sent; +uint8_t last_can_payload_sent[8]; uint8_t last_can_payload_size; bool can_frame_was_sent; @@ -32,6 +32,12 @@ void debug(const char* format, ...) { void mock_send_can(const uint16_t arbitration_id, const uint8_t* data, const uint8_t size) { + can_frame_was_sent = true; + last_can_frame_sent_arb_id = arbitration_id; + last_can_payload_size = size; + if(size > 0) { + memcpy(last_can_payload_sent, data, size); + } } void mock_set_timer(uint16_t time_ms, void (*callback)) { @@ -73,13 +79,6 @@ void can_frame_sent(const uint16_t arbitration_id, for(int i = 0; i < size; i++) { debug("0x%x", payload[i]); } - - can_frame_was_sent = true; - last_can_frame_sent_arb_id = arbitration_id; - last_can_payload_sent = size; - if(size > 0) { - memcpy(last_can_payload_sent, payload, size); - } } void setup() { @@ -88,6 +87,7 @@ void setup() { can_frame_sent); last_message_sent_payload = malloc(MAX_ISO_TP_MESSAGE_SIZE); last_message_received_payload = malloc(MAX_ISO_TP_MESSAGE_SIZE); + memset(last_can_payload_sent, 0, sizeof(last_can_payload_sent)); last_message_sent_status = false; message_was_received = false; can_frame_was_sent = false; diff --git a/tests/test_send.c b/tests/test_send.c index c2293c21..f5037536 100644 --- a/tests/test_send.c +++ b/tests/test_send.c @@ -9,7 +9,7 @@ extern IsoTpShims SHIMS; extern IsoTpHandler ISOTP_HANDLER; extern uint16_t last_can_frame_sent_arb_id; -extern uint8_t last_can_payload_sent; +extern uint8_t last_can_payload_sent[8]; extern uint8_t last_can_payload_size; extern bool can_frame_was_sent; @@ -32,6 +32,11 @@ START_TEST (test_send_empty_payload) fail_unless(last_message_sent_status); ck_assert_int_eq(last_message_sent_payload[0], NULL); ck_assert_int_eq(last_message_sent_payload_size, 0); + + ck_assert_int_eq(last_can_frame_sent_arb_id, ISOTP_HANDLER.arbitration_id); + fail_unless(can_frame_was_sent); + ck_assert_int_eq(last_can_payload_sent[0], 0x0); + ck_assert_int_eq(last_can_payload_size, 1); } END_TEST @@ -44,6 +49,13 @@ START_TEST (test_send_single_frame) ck_assert_int_eq(last_message_sent_payload[0], 0x12); ck_assert_int_eq(last_message_sent_payload[1], 0x34); ck_assert_int_eq(last_message_sent_payload_size, 2); + + ck_assert_int_eq(last_can_frame_sent_arb_id, ISOTP_HANDLER.arbitration_id); + fail_unless(can_frame_was_sent); + ck_assert_int_eq(last_can_payload_sent[0], 0x2); + ck_assert_int_eq(last_can_payload_sent[1], 0x12); + ck_assert_int_eq(last_can_payload_sent[2], 0x34); + ck_assert_int_eq(last_can_payload_size, 3); } END_TEST @@ -53,6 +65,8 @@ START_TEST (test_send_multi_frame) 0x45, 0x67, 0x89}; bool status = isotp_send(&ISOTP_HANDLER, &payload, sizeof(payload)); fail_if(status); + fail_if(last_message_sent_status); + fail_if(can_frame_was_sent); } END_TEST |