summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/common.c6
-rw-r--r--tests/test_receive.c10
-rw-r--r--tests/test_send.c30
3 files changed, 27 insertions, 19 deletions
diff --git a/tests/common.c b/tests/common.c
index 833a5ed4..4ad8eff1 100644
--- a/tests/common.c
+++ b/tests/common.c
@@ -5,7 +5,7 @@
#include <stdarg.h>
IsoTpShims SHIMS;
-IsoTpHandler ISOTP_HANDLER;
+IsoTpHandle HANDLE;
uint16_t last_can_frame_sent_arb_id;
uint8_t last_can_payload_sent[8];
@@ -83,8 +83,8 @@ void can_frame_sent(const uint16_t arbitration_id, const uint8_t* payload,
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);
+ // TODO
+ /* HANDLE = isotp_receive(&SHIMS, 0x2a, message_received); */
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));
diff --git a/tests/test_receive.c b/tests/test_receive.c
index b116dd23..17df9046 100644
--- a/tests/test_receive.c
+++ b/tests/test_receive.c
@@ -6,7 +6,7 @@
#include <stdarg.h>
extern IsoTpShims SHIMS;
-extern IsoTpHandler ISOTP_HANDLER;
+extern IsoTpHandle HANDLE;
extern uint16_t last_can_frame_sent_arb_id;
extern uint8_t last_can_payload_sent;
@@ -28,7 +28,7 @@ extern void setup();
START_TEST (test_receive_wrong_id)
{
const uint8_t data[CAN_MESSAGE_BYTE_SIZE] = {0};
- isotp_receive_can_frame(&ISOTP_HANDLER, 0x100, data, 1);
+ isotp_receive_can_frame(&SHIMS, &HANDLE, 0x100, data, 1);
fail_if(message_was_received);
}
END_TEST
@@ -37,7 +37,7 @@ START_TEST (test_receive_bad_pci)
{
// 4 is a reserved number for the PCI field - only 0-3 are allowed
const uint8_t data[CAN_MESSAGE_BYTE_SIZE] = {0x40};
- isotp_receive_can_frame(&ISOTP_HANDLER, 0x2a, data, 1);
+ isotp_receive_can_frame(&SHIMS, &HANDLE, 0x2a, data, 1);
fail_if(message_was_received);
}
END_TEST
@@ -45,7 +45,7 @@ END_TEST
START_TEST (test_receive_single_frame_empty_payload)
{
const uint8_t data[CAN_MESSAGE_BYTE_SIZE] = {0x00, 0x12, 0x34};
- isotp_receive_can_frame(&ISOTP_HANDLER, 0x2a, data, 3);
+ isotp_receive_can_frame(&SHIMS, &HANDLE, 0x2a, data, 3);
fail_unless(message_was_received);
ck_assert_int_eq(last_message_received_arb_id, 0x2a);
ck_assert_int_eq(last_message_received_payload_size, 0);
@@ -55,7 +55,7 @@ END_TEST
START_TEST (test_receive_single_frame)
{
const uint8_t data[CAN_MESSAGE_BYTE_SIZE] = {0x02, 0x12, 0x34};
- isotp_receive_can_frame(&ISOTP_HANDLER, 0x2a, data, 3);
+ isotp_receive_can_frame(&SHIMS, &HANDLE, 0x2a, data, 3);
fail_unless(message_was_received);
ck_assert_int_eq(last_message_received_arb_id, 0x2a);
ck_assert_int_eq(last_message_received_payload_size, 2);
diff --git a/tests/test_send.c b/tests/test_send.c
index f5037536..599552ae 100644
--- a/tests/test_send.c
+++ b/tests/test_send.c
@@ -6,7 +6,9 @@
#include <stdarg.h>
extern IsoTpShims SHIMS;
-extern IsoTpHandler ISOTP_HANDLER;
+extern IsoTpHandle 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[8];
@@ -27,13 +29,16 @@ 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);
+ uint16_t arbitration_id = 0x2a;
+ IsoTpHandle foo = isotp_send(&SHIMS, arbitration_id, NULL, 0, message_sent);
+ fail_unless(handle.success);
+ fail_unless(handle.completed);
+ ck_assert_int_eq(last_message_sent_arb_id, 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);
- ck_assert_int_eq(last_can_frame_sent_arb_id, ISOTP_HANDLER.arbitration_id);
+ ck_assert_int_eq(last_can_frame_sent_arb_id, 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);
@@ -43,14 +48,16 @@ END_TEST
START_TEST (test_send_single_frame)
{
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);
+ uint16_t arbitration_id = 0x2a;
+ IsoTpHandle handle = isotp_send(&SHIMS, arbitration_id, payload, sizeof(payload),
+ message_sent);
+ ck_assert_int_eq(last_message_sent_arb_id, 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);
- ck_assert_int_eq(last_can_frame_sent_arb_id, ISOTP_HANDLER.arbitration_id);
+ ck_assert_int_eq(last_can_frame_sent_arb_id, 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);
@@ -63,10 +70,11 @@ START_TEST (test_send_multi_frame)
{
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);
- fail_if(last_message_sent_status);
- fail_if(can_frame_was_sent);
+ uint16_t arbitration_id = 0x2a;
+ IsoTpHandle handle = isotp_send(&SHIMS, arbitration_id, payload, sizeof(payload),
+ message_sent);
+ fail_unless(handle.completed);
+ fail_if(handle.success);
}
END_TEST