summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/common.c18
-rw-r--r--tests/test_send.c24
2 files changed, 35 insertions, 7 deletions
diff --git a/tests/common.c b/tests/common.c
index 9aff39a1..512adfbc 100644
--- a/tests/common.c
+++ b/tests/common.c
@@ -44,11 +44,13 @@ void message_received(const uint16_t arbitration_id, const uint8_t* payload,
log_isotp_message(arbitration_id, payload, size);
last_message_received_arb_id = arbitration_id;
last_message_received_payload_size = size;
- memcpy(last_message_received_payload, payload, size);
+ if(size > 0) {
+ memcpy(last_message_received_payload, payload, size);
+ }
}
-void message_sent(const bool success, const uint16_t arbitration_id,
- const uint8_t* payload, const uint16_t size) {
+void message_sent(const uint16_t arbitration_id, const uint8_t* payload,
+ const uint16_t size, const bool success) {
if(success) {
debug("Sent ISO-TP message:");
} else {
@@ -58,7 +60,10 @@ void message_sent(const bool success, const uint16_t arbitration_id,
last_message_sent_arb_id = arbitration_id;
last_message_sent_payload_size = size;
- memcpy(last_message_sent_payload, payload, size);
+ last_message_sent_status = success;
+ if(size > 0) {
+ memcpy(last_message_sent_payload, payload, size);
+ }
}
void can_frame_sent(const uint16_t arbitration_id,
@@ -72,13 +77,16 @@ void can_frame_sent(const uint16_t arbitration_id,
can_frame_was_sent = true;
last_can_frame_sent_arb_id = arbitration_id;
last_can_payload_sent = size;
- memcpy(last_can_payload_sent, payload, size);
+ if(size > 0) {
+ memcpy(last_can_payload_sent, payload, size);
+ }
}
void setup() {
SHIMS = isotp_init_shims(debug, mock_send_can, mock_set_timer);
ISOTP_HANDLER = isotp_init(&SHIMS, 0x2a, message_received, message_sent,
can_frame_sent);
+ last_message_sent_payload = malloc(MAX_ISO_TP_MESSAGE_SIZE);
last_message_received_payload = malloc(MAX_ISO_TP_MESSAGE_SIZE);
last_message_sent_status = false;
message_was_received = false;
diff --git a/tests/test_send.c b/tests/test_send.c
index 144e040f..c2293c21 100644
--- a/tests/test_send.c
+++ b/tests/test_send.c
@@ -25,15 +25,34 @@ extern uint8_t last_message_sent_payload_size;
extern void setup();
+START_TEST (test_send_empty_payload)
+{
+ fail_unless(isotp_send(&ISOTP_HANDLER, NULL, 0));
+ ck_assert_int_eq(last_message_sent_arb_id, ISOTP_HANDLER.arbitration_id);
+ 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);
+}
+END_TEST
+
START_TEST (test_send_single_frame)
{
- fail_if(true);
+ const uint8_t payload[] = {0x12, 0x34};
+ fail_unless(isotp_send(&ISOTP_HANDLER, &payload, sizeof(payload)));
+ ck_assert_int_eq(last_message_sent_arb_id, ISOTP_HANDLER.arbitration_id);
+ fail_unless(last_message_sent_status);
+ 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);
}
END_TEST
START_TEST (test_send_multi_frame)
{
- fail_if(true);
+ const uint8_t payload[] = {0x12, 0x34, 0x56, 0x78, 0x90, 0x01, 0x23,
+ 0x45, 0x67, 0x89};
+ bool status = isotp_send(&ISOTP_HANDLER, &payload, sizeof(payload));
+ fail_if(status);
}
END_TEST
@@ -41,6 +60,7 @@ Suite* testSuite(void) {
Suite* s = suite_create("iso15765");
TCase *tc_core = tcase_create("send");
tcase_add_checked_fixture(tc_core, setup, NULL);
+ tcase_add_test(tc_core, test_send_empty_payload);
tcase_add_test(tc_core, test_send_single_frame);
tcase_add_test(tc_core, test_send_multi_frame);
suite_add_tcase(s, tc_core);