From 0bd237bae324740d6b6b22e3c63ac426267d5bf1 Mon Sep 17 00:00:00 2001 From: Christopher Peplin Date: Mon, 30 Dec 2013 20:49:23 -0500 Subject: [PATCH] Add more failing tests before beginning implementation. --- src/obd2/obd2.h | 2 ++ tests/test_core.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/obd2/obd2.h b/src/obd2/obd2.h index 411170da..74459520 100644 --- a/src/obd2/obd2.h +++ b/src/obd2/obd2.h @@ -112,6 +112,8 @@ typedef enum { typedef struct { IsoTpHandler isotp_handler; + // TODO the Handle may need to keep the original request, otherwise we can't + // compare an incoming CAN message to see if it matches the service / PID! DiagnosticRequestType type; DiagnosticResponseReceived callback; DiagnosticMilStatusReceived mil_status_callback; diff --git a/tests/test_core.c b/tests/test_core.c index 35e948ee..340a3268 100644 --- a/tests/test_core.c +++ b/tests/test_core.c @@ -12,7 +12,18 @@ extern DiagnosticResponseReceived response_received_handler; START_TEST (test_receive_wrong_arb_id) { - ck_assert(false); + DiagnosticRequest request = { + arbitration_id: 0x7df, + mode: OBD2_MODE_POWERTRAIN_DIAGNOSTIC_REQUEST + }; + DiagnosticRequestHandle handle = diagnostic_request(&SHIMS, &request, + response_received_handler); + + fail_if(last_response_was_received); + const uint8_t can_data[] = {0x2, request.mode + 0x40, 0x23}; + diagnostic_receive_can_frame(&handle, request.arbitration_id, can_data, + sizeof(can_data)); + fail_if(last_response_was_received); } END_TEST @@ -43,16 +54,45 @@ END_TEST START_TEST (test_request_pid_standard) { - fail_unless(false); - // TODO test request pid, do the same rigamarole - // kind of leaky, but check that the returned DiagnosticRequest Handle - // has the right PID + DiagnosticRequestHandle handle = diagnostic_request_pid(&SHIMS, + DIAGNOSTIC_STANDARD_PID, 0x2, response_received_handler); + + fail_if(last_response_was_received); + const uint8_t can_data[] = {0x3, 0x1 + 0x40, 0x2, 0x45}; + // TODO need a constant for the 7df broadcast functional request + diagnostic_receive_can_frame(&handle, 0x7df + 0x8, + can_data, sizeof(can_data)); + fail_unless(last_response_was_received); + ck_assert(last_response_received.success); + ck_assert_int_eq(last_response_received.arbitration_id, + 0x7df + 0x8); + // TODO should we set it back to the original mode, or leave as mode + 0x40? + ck_assert_int_eq(last_response_received.mode, 0x1); + ck_assert_int_eq(last_response_received.pid, 0x2); + ck_assert_int_eq(last_response_received.payload_length, 1); + ck_assert_int_eq(last_response_received.payload[0], can_data[3]); } END_TEST START_TEST (test_request_pid_enhanced) { - fail_unless(false); + DiagnosticRequestHandle handle = diagnostic_request_pid(&SHIMS, + DIAGNOSTIC_ENHANCED_PID, 0x2, response_received_handler); + + fail_if(last_response_was_received); + const uint8_t can_data[] = {0x4, 0x1 + 0x40, 0x0, 0x2, 0x45}; + // TODO need a constant for the 7df broadcast functional request + diagnostic_receive_can_frame(&handle, 0x7df + 0x8, can_data, + sizeof(can_data)); + fail_unless(last_response_was_received); + ck_assert(last_response_received.success); + ck_assert_int_eq(last_response_received.arbitration_id, + 0x7df + 0x8); + // TODO should we set it back to the original mode, or leave as mode + 0x40? + ck_assert_int_eq(last_response_received.mode, 0x22); + ck_assert_int_eq(last_response_received.pid, 0x2); + ck_assert_int_eq(last_response_received.payload_length, 1); + ck_assert_int_eq(last_response_received.payload[0], can_data[4]); } END_TEST -- 2.16.6