aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChristopher Peplin <chris.peplin@rhubarbtech.com>2013-12-30 20:40:50 -0500
committerChristopher Peplin <chris.peplin@rhubarbtech.com>2013-12-30 20:40:50 -0500
commit217bb7fd1657e35a95024bb5bda598ea136fdfbe (patch)
tree5dab9acd9b5793baf7d413b59f5c12801bcad404 /tests
parent32f4cbab6bd5769a4b16a584e1880b1deabbd2da (diff)
Add a failing test for a simple diag request/response.
Diffstat (limited to 'tests')
-rw-r--r--tests/common.c50
-rw-r--r--tests/test_core.c59
2 files changed, 106 insertions, 3 deletions
diff --git a/tests/common.c b/tests/common.c
index e69de29b..e35ef529 100644
--- a/tests/common.c
+++ b/tests/common.c
@@ -0,0 +1,50 @@
+#include <obd2/obd2.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+DiagnosticShims SHIMS;
+
+uint16_t last_can_frame_sent_arb_id;
+uint8_t last_can_payload_sent[8];
+uint8_t last_can_payload_size;
+bool can_frame_was_sent;
+
+DiagnosticResponse last_response_received;
+bool last_response_was_received;
+
+void debug(const char* format, ...) {
+ va_list args;
+ va_start(args, format);
+ vprintf(format, args);
+ printf("\r\n");
+ va_end(args);
+}
+
+void mock_send_can(const uint16_t arbitration_id, const uint8_t* data,
+ const uint8_t size) {
+ can_frame_was_sent = true;
+ last_can_frame_sent_arb_id = arbitration_id;
+ last_can_payload_size = size;
+ if(size > 0) {
+ memcpy(last_can_payload_sent, data, size);
+ }
+}
+
+void mock_set_timer(uint16_t time_ms, void (*callback)) {
+}
+
+void response_received_handler(const DiagnosticResponse* response) {
+ last_response_was_received = true;
+ // TODO not sure if we can copy the struct like this
+ last_response_received = *response;
+}
+
+void setup() {
+ SHIMS = diagnostic_init_shims(debug, mock_send_can, mock_set_timer);
+ memset(last_can_payload_sent, 0, sizeof(last_can_payload_sent));
+ can_frame_was_sent = false;
+ last_response_was_received = false;
+}
+
diff --git a/tests/test_core.c b/tests/test_core.c
index 65af8580..35e948ee 100644
--- a/tests/test_core.c
+++ b/tests/test_core.c
@@ -1,13 +1,56 @@
+#include <obd2/obd2.h>
#include <check.h>
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
-void setup() {
+extern void setup();
+extern bool last_response_was_received;
+extern DiagnosticResponse last_response_received;
+extern DiagnosticShims SHIMS;
+extern DiagnosticResponseReceived response_received_handler;
+START_TEST (test_receive_wrong_arb_id)
+{
+ ck_assert(false);
}
+END_TEST
+
+START_TEST (test_send_diag_request)
+{
+ 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 + 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,
+ request.arbitration_id + 0x8);
+ // TODO should we set it back to the original mode, or leave as mode + 0x40?
+ 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
-START_TEST (test_fail)
+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
+}
+END_TEST
+
+START_TEST (test_request_pid_enhanced)
{
fail_unless(false);
}
@@ -17,7 +60,17 @@ Suite* testSuite(void) {
Suite* s = suite_create("obd2");
TCase *tc_core = tcase_create("core");
tcase_add_checked_fixture(tc_core, setup, NULL);
- tcase_add_test(tc_core, test_fail);
+ tcase_add_test(tc_core, test_send_diag_request);
+ tcase_add_test(tc_core, test_receive_wrong_arb_id);
+ tcase_add_test(tc_core, test_request_pid_standard);
+ tcase_add_test(tc_core, test_request_pid_enhanced);
+
+ // TODO these are future work:
+ // TODO test request MIL
+ // TODO test request VIN
+ // TODO test request DTC
+ // TODO test clear DTC
+ // TODO test enumerate PIDs
suite_add_tcase(s, tc_core);
return s;