Add more failing tests before beginning implementation.
authorChristopher Peplin <chris.peplin@rhubarbtech.com>
Tue, 31 Dec 2013 01:49:23 +0000 (20:49 -0500)
committerChristopher Peplin <chris.peplin@rhubarbtech.com>
Tue, 31 Dec 2013 01:49:23 +0000 (20:49 -0500)
src/obd2/obd2.h
tests/test_core.c

index 411170d..7445952 100644 (file)
@@ -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;
index 35e948e..340a326 100644 (file)
@@ -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