diff options
author | Christopher Peplin <chris.peplin@rhubarbtech.com> | 2014-01-02 17:15:24 -0500 |
---|---|---|
committer | Christopher Peplin <chris.peplin@rhubarbtech.com> | 2014-01-02 17:15:24 -0500 |
commit | 8e574cb4798a928ac50ffe6cb4fa5e3d22b8003a (patch) | |
tree | 56f8ab5c1eecc9163be48f7668e10460c63b4d83 /tests | |
parent | 54713fc5deab5de318d79035a0927d828ae239f5 (diff) |
Test basic diag request and response!
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_core.c | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/tests/test_core.c b/tests/test_core.c index 2730cd7..4b24734 100644 --- a/tests/test_core.c +++ b/tests/test_core.c @@ -62,18 +62,19 @@ END_TEST START_TEST (test_request_pid_standard) { + // TODO need a constant for the 7df broadcast functional request + uint16_t arb_id = 0x7df; DiagnosticRequestHandle handle = diagnostic_request_pid(&SHIMS, - DIAGNOSTIC_STANDARD_PID, 0x2, response_received_handler); + DIAGNOSTIC_STANDARD_PID, arb_id, 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(&SHIMS, &handle, 0x7df + 0x8, + diagnostic_receive_can_frame(&SHIMS, &handle, arb_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, - 0x7df + 0x8); + arb_id + 0x8); 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); @@ -83,19 +84,18 @@ END_TEST START_TEST (test_request_pid_enhanced) { + uint16_t arb_id = 0x7df; DiagnosticRequestHandle handle = diagnostic_request_pid(&SHIMS, - DIAGNOSTIC_ENHANCED_PID, 0x2, response_received_handler); + DIAGNOSTIC_ENHANCED_PID, arb_id, 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(&SHIMS, &handle, 0x7df + 0x8, can_data, + const uint8_t can_data[] = {0x4, 0x22 + 0x40, 0x0, 0x2, 0x45}; + diagnostic_receive_can_frame(&SHIMS, &handle, arb_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, - 0x7df + 0x8); - // TODO should we set it back to the original mode, or leave as mode + 0x40? + arb_id + 0x8); 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); @@ -103,6 +103,21 @@ START_TEST (test_request_pid_enhanced) } END_TEST +START_TEST (test_wrong_mode_response) +{ + uint16_t arb_id = 0x7df; + DiagnosticRequestHandle handle = diagnostic_request_pid(&SHIMS, + DIAGNOSTIC_ENHANCED_PID, arb_id, 0x2, response_received_handler); + + fail_if(last_response_was_received); + const uint8_t can_data[] = {0x4, 0x1 + 0x40, 0x0, 0x2, 0x45}; + diagnostic_receive_can_frame(&SHIMS, &handle, arb_id + 0x8, can_data, + sizeof(can_data)); + fail_unless(last_response_was_received); + fail_if(last_response_received.success); +} +END_TEST + Suite* testSuite(void) { Suite* s = suite_create("obd2"); TCase *tc_core = tcase_create("core"); @@ -111,6 +126,7 @@ Suite* testSuite(void) { 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); + tcase_add_test(tc_core, test_wrong_mode_response); // TODO these are future work: // TODO test request MIL |