summaryrefslogtreecommitdiffstats
path: root/CAN-binder/libs/isotp-c/tests/test_send.c
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-05-02 17:51:18 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-05-02 17:51:18 +0200
commitf44a5b1549bc4c8a84d0dedf4a8b1e4220a34f42 (patch)
tree2368f764aa2f10bf9927096f5222dc4cab94a838 /CAN-binder/libs/isotp-c/tests/test_send.c
parentd170c9faeae2cf29c19f3523714ecdf58be73bed (diff)
parentee24440b7c123ab1b0317e57be33e837a1cb51f1 (diff)
Add 'CAN-binder/libs/isotp-c/' from commit 'ee24440b7c123ab1b0317e57be33e837a1cb51f1'
git-subtree-dir: CAN-binder/libs/isotp-c git-subtree-mainline: d170c9faeae2cf29c19f3523714ecdf58be73bed git-subtree-split: ee24440b7c123ab1b0317e57be33e837a1cb51f1
Diffstat (limited to 'CAN-binder/libs/isotp-c/tests/test_send.c')
-rw-r--r--CAN-binder/libs/isotp-c/tests/test_send.c103
1 files changed, 103 insertions, 0 deletions
diff --git a/CAN-binder/libs/isotp-c/tests/test_send.c b/CAN-binder/libs/isotp-c/tests/test_send.c
new file mode 100644
index 00000000..29cf5dec
--- /dev/null
+++ b/CAN-binder/libs/isotp-c/tests/test_send.c
@@ -0,0 +1,103 @@
+#include <isotp/receive.h>
+#include <check.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+extern IsoTpShims SHIMS;
+
+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];
+extern uint8_t last_can_payload_size;
+extern bool can_frame_was_sent;
+
+extern bool message_was_received;
+extern uint16_t last_message_received_arb_id;
+extern uint8_t last_message_received_payload[];
+extern uint8_t last_message_received_payload_size;
+
+extern uint16_t last_message_sent_arb_id;
+extern bool last_message_sent_status;
+extern uint8_t last_message_sent_payload[];
+extern uint8_t last_message_sent_payload_size;
+
+extern void setup();
+
+START_TEST (test_send_empty_payload)
+{
+ SHIMS.frame_padding = false;
+ uint16_t arbitration_id = 0x2a;
+ IsoTpSendHandle handle = 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], '\0');
+ ck_assert_int_eq(last_message_sent_payload_size, 0);
+
+ 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);
+}
+END_TEST
+
+START_TEST (test_send_single_frame)
+{
+ SHIMS.frame_padding = false;
+ const uint8_t payload[] = {0x12, 0x34};
+ uint16_t arbitration_id = 0x2a;
+ 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, 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
+
+START_TEST (test_send_multi_frame)
+{
+ const uint8_t payload[] = {0x12, 0x34, 0x56, 0x78, 0x90, 0x01, 0x23,
+ 0x45, 0x67, 0x89};
+ uint16_t arbitration_id = 0x2a;
+ IsoTpSendHandle handle = isotp_send(&SHIMS, arbitration_id, payload, sizeof(payload),
+ message_sent);
+ fail_unless(handle.completed);
+ fail_if(handle.success);
+}
+END_TEST
+
+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);
+
+ return s;
+}
+
+int main(void) {
+ int numberFailed;
+ Suite* s = testSuite();
+ SRunner *sr = srunner_create(s);
+ // Don't fork so we can actually use gdb
+ srunner_set_fork_status(sr, CK_NOFORK);
+ srunner_run_all(sr, CK_NORMAL);
+ numberFailed = srunner_ntests_failed(sr);
+ srunner_free(sr);
+ return (numberFailed == 0) ? 0 : 1;
+}