aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Peplin <chris.peplin@rhubarbtech.com>2013-12-30 20:49:23 -0500
committerChristopher Peplin <chris.peplin@rhubarbtech.com>2013-12-30 20:49:23 -0500
commit0bd237bae324740d6b6b22e3c63ac426267d5bf1 (patch)
tree17843ac709dd8de274c784046735ee13ef6a1053
parent217bb7fd1657e35a95024bb5bda598ea136fdfbe (diff)
Add more failing tests before beginning implementation.
-rw-r--r--src/obd2/obd2.h2
-rw-r--r--tests/test_core.c52
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