summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Peplin <chris.peplin@rhubarbtech.com>2014-01-03 14:54:02 -0500
committerChristopher Peplin <chris.peplin@rhubarbtech.com>2014-01-03 14:54:02 -0500
commit183ee8ad424f06850af903668314d7e9cda9a3e0 (patch)
tree16cb675beeb40505b998f13b4df8675ed0021dea
parent6876f328d9a442275c9b6e0a6a6d2db14ae3a35c (diff)
Test receiving a CAN frame to an already completed message.
-rw-r--r--tests/test_core.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/test_core.c b/tests/test_core.c
index 88a753d7..dbe2eadc 100644
--- a/tests/test_core.c
+++ b/tests/test_core.c
@@ -146,6 +146,40 @@ START_TEST (test_wrong_mode_response)
}
END_TEST
+START_TEST (test_handle_completed)
+{
+ DiagnosticRequest request = {
+ arbitration_id: 0x7df,
+ mode: OBD2_MODE_POWERTRAIN_DIAGNOSTIC_REQUEST
+ };
+ DiagnosticRequestHandle handle = diagnostic_request(&SHIMS, &request,
+ response_received_handler);
+
+ fail_if(handle.completed);
+
+ const uint8_t can_data[] = {0x2, request.mode + 0x40, 0x23};
+ DiagnosticResponse response = diagnostic_receive_can_frame(&SHIMS, &handle,
+ request.arbitration_id + 0x8, can_data, sizeof(can_data));
+ fail_unless(response.success);
+ fail_unless(response.completed);
+ fail_unless(handle.completed);
+
+ response = diagnostic_receive_can_frame(&SHIMS, &handle,
+ request.arbitration_id + 0x8, can_data, sizeof(can_data));
+ fail_if(response.success);
+ fail_if(response.completed);
+ fail_unless(handle.completed);
+
+ ck_assert(last_response_received.success);
+ ck_assert_int_eq(last_response_received.arbitration_id,
+ request.arbitration_id + 0x8);
+ ck_assert_int_eq(last_response_received.mode, request.mode);
+ ck_assert_int_eq(last_response_received.pid, 0);
+ ck_assert_int_eq(last_response_received.payload_length, 1);
+ ck_assert_int_eq(last_response_received.payload[0], can_data[2]);
+}
+END_TEST
+
Suite* testSuite(void) {
Suite* s = suite_create("obd2");
TCase *tc_core = tcase_create("core");
@@ -156,6 +190,7 @@ Suite* testSuite(void) {
tcase_add_test(tc_core, test_request_pid_standard);
tcase_add_test(tc_core, test_request_pid_enhanced);
tcase_add_test(tc_core, test_wrong_mode_response);
+ tcase_add_test(tc_core, test_handle_completed);
// TODO these are future work:
// TODO test request MIL